<!-- 通知消息 -->
<template>
	<view class="container">
		<view class="notice-list" v-if="list.length>0">
			<template v-for="item in list">
				<view class="notice-item"
					@longpress="del_news(item.id)"
					@click="read(item.id)"
					:key="item.id" v-if="item.type==4">
					<view>
						提现成功
					</view>
					<view>
						{{item.msg}}
					</view>
					<view>
						{{item.created_at}}
					</view>
				</view>
			</template>
		</view>
		<view class="nodata" v-else>
			<image
			src="https://community.chuangxiangdianli.com/images/empty/nomessage.png" mode=""></image>
		</view>
		<u-loadmore :status="status" />
	</view>
</template>
<!-- js -->
<script>
	// 引入封装的请求
	import request from '@/utils/request.js'
	export default {
		data() {
			return {
				list:[],
				// 当前页码
				pageNo:1,
				// 列表个数 
				limit:10,
				// 是否正在请求数据
				is_loading:false,
				// 是否请求完数据
				is_bottom:false,
				// 底部正在加载中
				status: 'loadmore',
			}
		},
		computed: {
			
		},
		watch: {
			
		},
		onLoad() {
			this.get_news_list()
		},
		onShow() {
			
		},
		// 页面底部加载
		onReachBottom(){
			let that = this
			this.status = 'loading';
			// console.log(11111)
			if(that.status = 'nomore' || that.is_loading){
				return false
			}
			this.pageNo++
			setTimeout(() => {
				that.get_news_list(true)
			}, 1000)
		},
		methods: {
			// 点击已读
			read(id){
				let that = this
				request.get('Mini/circle/flea/readNotice',{
					ids:id
				},'none').then(res=>{
				})
			},
			// 删除
			del_news(id){
				let that = this
				uni.showModal({
				    title: '提示',
				    content: '确定删除当前消息吗',
				    success: function (res) {
				        if (res.confirm) {
							this.$mrequest2({
								url:'Mini/circle/flea/destroyNotice/'+id,
								method:'DELETE',
								data:{
									id
								}
							}).then(res=>{
								console.log(res)
								if(res.code==200){
									that.get_news_list()
								}
							})
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
			},
			// 获取消息列表
			get_news_list(turn){
				let that = this
				that.is_loading = true
				request.get('Mini/circle/flea/fleaNotice',{
					page:that.pageNo,
					limit:that.limit,
					type:2
				}).then(res=>{
					// console.log('首页数据', res)
					that.is_loading = false
					if (res.code==200) {
						if(turn){
							if(res.data.data.length>0){
								that.list = [
									...that.list,
									...res.data.data
								]
							}
						}else{
							that.list = res.data.data
						}
						if(res.data.count==that.list.length){
							// that.is_boottom = true
							that.status = 'nomore';
						}
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				}).catch(res => {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				})
			},
		}
	}
</script>
<!-- css -->
<style lang="scss" scoped>
	.container{
		width: 100vw;
		box-sizing: border-box;
		background-color: #FFFFFF;
		.nodata{
			width: 100%;
			display: flex;
			justify-content: center;
			&>image{
				width: 400rpx;
				height: 400rpx;
			}
		}
		.notice-list{
			width: 100%;
			box-sizing: border-box;
			padding: 0 30rpx;
			border-top: 2rpx solid transparent;
			margin-top: 23rpx;
			margin-bottom: 20rpx;
			.notice-item{
				margin-top: 39rpx;
				width: 690rpx;
				// height: 229rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 6rpx 40rpx 0rpx rgba(144, 144, 144, 0.39);
				border-radius: 15rpx;
				box-sizing: border-box;
				padding: 35rpx 42rpx;
				&>view{
					width: 100%;
				}
				&>view:nth-child(1),
				&>view:nth-child(2){
					margin-bottom: 41rpx;
				}
				&>view:nth-child(1){
					font-size: 30rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #333333;
				}
				&>view:nth-child(2){
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #333333;
					&>text{
						color: #FF1212;
					}
				}
				&>view:nth-child(3){
					text-align: right;
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
				}
			}
		}
	}
</style>
